
package com.datawin.taotaocheche.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.datawin.taotaocheche.R;
import com.datawin.taotaocheche.bean.ClueInfo;
import com.datawin.taotaocheche.comm.Constants;
import com.datawin.taotaocheche.ui.actviity.user.CustomAct;
import com.datawin.taotaocheche.util.StringUtils;
import com.datawin.taotaocheche.util.SysUtils;
import com.superrecycleview.superlibrary.adapter.BaseViewHolder;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;

import java.util.Date;
import java.util.List;

/**
 * chenjian
 */
public class ClueAdapter extends SuperBaseAdapter<ClueInfo> {
    Context mContext;

    public ClueAdapter(Context context, List<ClueInfo> data) {
        super(context, data);
        mContext = context;


    }


    @Override
    protected void convert(BaseViewHolder holder, final ClueInfo item, final int position) {
        String info = (StringUtils.isEmpty(item.getCity()) ? "" : item.getCity()) + (StringUtils.isEmpty(item.getAge()) ? "" : " |" + item.getAge()+"年")
                + (StringUtils.isEmpty(item.getZhiye()) ? "" : " |" + item.getZhiye()+"公里") + (StringUtils.isEmpty(item.getShouru()) ? "" : "  |车型" + item.getShouru());
        holder.setText(R.id.item_collection_name, item.getName()).setText(R.id.item_collection_phone, item.getMobile()).
                setText(R.id.item_collection_car, item.getTrainingType()).setText(R.id.item_collection_tip, info).
                setText(R.id.item_collection_time, "更新时间：" + SysUtils.getDatePoorNew(new Date(),item.getUpdateTime()));

        TextView state = holder.getView(R.id.item_collection_state);
        if (item.getSoldQuantity() >= item.getUseCount()) {
            state.setText("已抢完");
            state.setBackgroundResource(R.drawable.bg_shape_gray);
        } else if (item.getSoldQuantity() == 0) {
            state.setText("马上抢");
            state.setBackgroundResource(R.drawable.bg_shape_red);
        } else if (item.getSoldQuantity() < item.getUseCount() && item.getSoldQuantity() > 0) {
            state.setText("已抢" + item.getSoldQuantity() + "/" + item.getUseCount());
            state.setBackgroundResource(R.drawable.bg_shape_green);
        }

        holder.getView(R.id.item_collection_layout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, CustomAct.class);
                intent.putExtra("position",position+"");
                intent.putExtra(Constants.KEYSTRING, item.getStudentCode());
                mContext.startActivity(intent);
            }
        });
        state.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, CustomAct.class);
                intent.putExtra("position",position+"");
                intent.putExtra(Constants.KEYSTRING, item.getStudentCode());
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    protected int getItemViewLayoutId(int position, ClueInfo item) {
        return R.layout.item_clue;
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {

    }


}